You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

get-random-values

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-random-values

`window.crypto.getRandomValues` with fallback to Node.js crypto

3.0.0
latest
Source
npm
Version published
Weekly downloads
212K
-2.02%
Maintainers
1
Weekly downloads
 
Created
Source

get-random-values

window.crypto.getRandomValues or window.msCrypto.getRandomValues or require('crypto').randomBytes or an Error.

Example

var getRandomValues = require('get-random-values');

var array = new Uint32Array(10);
getRandomValues(array);
// => [
// =>   183,
// =>   76,
// =>   18,
// =>   177,
// =>   73,
// =>   9,
// =>   50,
// =>   248,
// =>   216,
// =>   104
// => ]

Installation

$ npm install get-random-values

API

var getRandomValues = require('get-random-values');

getRandomValues(buf)

Fills integer-based TypedArray buf with cryptographically random numbers. Checks for and uses the first of the following:

  • window.crypto.getRandomValues
  • window.msCrypto.getRandomValues
  • Node.js crypto

If none of the above are available, then an Error is thrown.

Throws QuotaExceededError if buf.length > 65536 (even if Node.js crypto, which doesn't have that limit, is being used).

buf must be a Uint8Array if Node.js crypto is used, otherwise a TypeError will be thrown.

Keywords

crypto

FAQs

Package last updated on 21 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts